import { MaybeRef, Ref } from "vue"
import { PaginationParams, PagedResponse } from "./pagination"

/**
 * DataSourceReturnType 表示创建执行查询返回的结果
 *
 * @property 是否正在执行查询的响应式结果
 * @property 返回响应式结果
 * @property 返回响应式错误信息
 * @property 执行查询动作
 */
export interface DataSourceReturnType {
  isFetching: Readonly<Ref<boolean>>
  data: Ref<PagedResponse<any> | null>
  error: Ref<any>
  execute: (...args: any[]) => Promise<any>
}

/**
 * SearchParams 用于传递查询的参数
 */
export interface SearchParams {
  keyword: string
}

/**
 * SearchDataSource 传递查询参数和分页参数以查询数据
 *
 * @param params 搜索参数
 * @param pagination 分页参数
 */
export type SearchDataSource = (
  params: MaybeRef<SearchParams>,
  pagination: MaybeRef<PaginationParams>,
) => DataSourceReturnType

/**
 * QueryParams 用于传递多维查询参数
 */
export type QueryParams = Record<string, any>

/**
 * QueryDataSource 创建传递多维参数以查询数据的过程

 * @param params 查询参数
 * @param pagination 分页参数
 */
export type QueryDataSource = (
  params: MaybeRef<QueryParams>,
  pagination: MaybeRef<PaginationParams>,
) => DataSourceReturnType

/**
 * ClosuredDataSource 用于创建包含了查询条件的查询过程
 *
 * @param pagination 分页参数
 */
export type ClosuredDataSource = (
  pagination: MaybeRef<PaginationParams>,
) => DataSourceReturnType
